/**
 * 
 */
package vue.desktop;

import java.awt.Color;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;

import model.cnf.CNF;

/**
 * Show the basic information about a CNF.
 * 
 * 
 * @author GRONOWSKI Stephane svan001@aol.com
 * 
 *         igsat 2010
 * 
 */
public class IGDeskCNFInformation extends JPanel {

	private static final long	serialVersionUID		= 1L;

	public static final int		MAX_SIZE_NAME			= 17;

	public static final String	DEFAULT_STRING			= "UNKNOW";
	public static final String	DEFAULT_CLAUSE_PREFIX	= "#Clause : ";
	public static final String	DEFAULT_VAR_PREFIX		= "#Variable : ";

	private JLabel				name;
	private JLabel				clause;
	private JLabel				variable;


	/**
	 * 
	 */
	public IGDeskCNFInformation(CNF cnf) {
		// TODO Auto-generated constructor stub
		setLayout(new GridLayout(3, 1));

		// name
		name = new JLabel(DEFAULT_STRING, JLabel.CENTER);
		name.setOpaque(true);
		name.setBackground(Color.GRAY);
		name.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		// name.setFont(Font.gFont.BOLD);
		// name.set

		clause = new JLabel(DEFAULT_CLAUSE_PREFIX + DEFAULT_STRING, JLabel.CENTER);
		clause.setBackground(Color.YELLOW);
		clause.setOpaque(true);
		clause.setBorder(BorderFactory.createLineBorder(Color.BLACK));

		variable = new JLabel(DEFAULT_VAR_PREFIX + DEFAULT_STRING, JLabel.CENTER);
		variable.setBackground(Color.YELLOW);
		variable.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		variable.setOpaque(true);

		add(name);
		add(clause);
		add(variable);
		refresh(cnf);

		// setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK));
		// setBorder(BorderFactory.createLineBorder(Color.BLACK));

	}

	public void refresh(CNF cnf) {
		if (cnf.getCNFfile().getName().length() > MAX_SIZE_NAME)
			name.setText(cnf.getCNFfile().getName().substring(0, MAX_SIZE_NAME));
		else
			name.setText(cnf.getCNFfile().getName());
		clause.setText(DEFAULT_CLAUSE_PREFIX + cnf.getDeclaredNumClause());
		variable.setText(DEFAULT_VAR_PREFIX + cnf.getDeclaredNumVar());
	}

}
